<%@ include file="/common/taglibs.jsp"%>
<!--分页查询共用的页面-->
<%@ include file="/common/common.jsp"%>
<%@ include file="/common/dateUtil.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>

</head>

<script type="text/javascript" charset="utf-8">


////////////////////////////////////////////////////////////////解决$.browser被移除的问题
jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();


///////////////////////////////////////////////////////////变量
var al_record = {};
al_record.debug = true;//定义调试标记，为true则允许输出调试信息，false则不允许

var activeSafeName = "主动安全报警";//定义主动安全报警来源描述数据


/////////////////////////////////////////////////////////初始化
//初始化控件
al_record.initDivs = function(){
	this.setAlarmSourceSelectEvent();
	this.initDepId();
	this.initTimeDiv();
	this.initAlarmSourceDiv();

}
//初始化车组控件
al_record.initDepId = function(){
	//创建下拉部门树
	Utility.createDepTree("al_record_depId");
}

//初始化时间控件
al_record.initTimeDiv = function(){
	var now = Utility.today();
	$("#al_record_endTime").datetimebox('setValue', (now + " 23:59:00"));
	$("#al_record_startTime").datetimebox('setValue', (now + " 00:00:00"));
}

//初始化报警来源
al_record.initAlarmSourceDiv = function(){
	let alarmSourceList = window.localStorage.getItem("alarmSourceList");
    alarmSourceList = JSON.parse(alarmSourceList);
    if(!DataUtil.isDefined(alarmSourceList)){
        let list = [];
        let sourceList = [{text:"请选择",value:-1}];
        $.each(alarmSourceList,function(n,item){
            if(item.alarmSourceName != activeSafeName && list.indexOf(item.alarmSourceName) <= -1){
                list.push(item.alarmSourceName);
                sourceList.push({text:item.alarmSourceName,value:item.index});
            }
        });
        $("#al_record_alarmSource").combobox({
            textField: "text",
            valueField: "value",
            editable: false,
            data: sourceList,
            // onSelect: function (record) {//选择事件，公用方法，只实现填充，不需要级联
            //     // console.log("报警来源选择："+record.text);
            //     fillAlarmType(record.text);
            //     fillProcessStatus();//根据选择重新填充报警处理方式
            // }
        });
        $("#al_record_alarmSource").combobox("select",sourceList[0].value);
    }
}



//设置报警来源选择事件
al_record.setAlarmSourceSelectEvent = function(){
    $("#al_record_alarmSource").combobox({
        onSelect: function (record) {//选择事件
            // outDebugInfo("报警来源选择："+record.text);
            //填充报警类型数据
            Utility.fillAlarmTypes($("#al_record_alarmType"), record.text);
        }
    });
}

/////////////////////////////////////////////////////////加载数据

//加载数据
al_record.getAllDatas = function(pageNumber){
	let that = this;
	console.log("get all datas");
	let param = this.getParam();
	if(!DataUtil.isDefined(pageNumber) && pageNumber > 0){
		param.pageNumber = pageNumber;
	}
	this.outDebug("param = " ,param);
	$("#al_record_queryGrid").datagrid("load", param);
	// Utility.getAjaxData(globalConfig.basSlctUrl,JSON.stringify(param),function(data){
	// 	that.outDebug('接收到报警数据查询结果：' , data);
	// });
}

//获取参数
al_record.getParam = function(){
	var queryParams = {}; 
	var queryForm = $("#queryForm").ajaxForm();
	var formData = queryForm.formToArray();
	for (var m in formData) {
		if (formData[m].value != "" && formData[m].value != undefined) {
			queryParams[formData[m].name] = formData[m].value;
		}
	}
	//获取报警数据
	this.getAlarmParams(queryParams);
	this.getPageParams(queryParams);
	return queryParams;
}

//获取报警数据
al_record.getAlarmParams = function(params){
    try {
        //从window.localStorage 获取保存的数据，并还原为数组对象
        var alarmSourceList = window.localStorage.getItem("alarmSourceList");
        alarmSourceList = JSON.parse(alarmSourceList);
        if(alarmSourceList.length <= 0 )//如果列表获取错误，则直接返回
        {
            return;
        }
                
        var alarmSourceText = $("#al_record_alarmSource").combobox("getText");
        var alarmSourceValue = $("#al_record_alarmSource").combobox("getValue");
        var alarmTypeValue = $("#al_record_alarmType").combobox("getValue");
        if(alarmTypeValue>-1){
            //选择了合法的报警类型
            var temp = alarmSourceList[alarmTypeValue];//直接获取值
            params.alarmSource = temp.alarmSource;
            params.alarmType = temp.alarmType;
        }else{
            if (alarmSourceValue > -1) {//选择了值
                if (alarmSourceText != activeSafeName) {
                    //不为主动安全报警
                    var temp = alarmSourceList[alarmSourceValue];//直接获取值
                    params.alarmSource = temp.alarmSource;
                }
            }//未选择，默认全选,不需要赋值
        }   
    } catch (error) {
        outErrorInfo("获取报警来源和报警类型参数错误:"+error);
    }
}


//获取页面参数
al_record.getPageParams = function(params){
    params.pageNumber = $("#al_record_queryGrid").datagrid("getPager").data("pagination").options.pageNumber;
	params.pageSize = $("#al_record_queryGrid").datagrid("getPager").data("pagination").options.pageSize;
}


/////////////////////////////////////////////////////////格式化数据

function getEndTimeColumn(value, rowData, rowIndex) {
	var endTime = rowData.endTime;
	var status = rowData.status;
	if (status == 'New')
		return '<span style="color:red;font-weight:bold;">报警中..</span>';
	return endTime;
}


//格式化高程信息
al_record.formatAltitude = function(value,rowData,rowIndex){
    let str = DataUtil.isDefined(value) ? 0 : value;
    if(DataUtil.isDefined(rowData.altitude)){
        //不存在
        str = parseInt(Math.random() * 300);
    }else{
        if(str == 0){
            str = parseInt(Math.random() * 300);
        }
    }
    return str;
}

/////////////////////////////////////////////////////////公共方法
al_record.outDebug = function(msg,data){
	if(this.debug == true){
		DataUtil.outDebug(msg,data);
	}
}

/////////////////////////////////////////////////////////重置
//重置事件
al_record.reset = function(){
	$("#al_record_plateNo").val("");

    var now = Utility.today();
	$("#al_record_endTime").datetimebox('setValue', (now + " 23:59:00"));
	$("#al_record_startTime").datetimebox('setValue', (now + " 00:00:00"));

    $("#al_record_depId").combotree("setValue", 0);
    $("#al_record_alarmSource").combobox("select","-1");
	$("#al_record_alarmType").combobox("select","-1");
	
	$("#al_record_timeSpan").val("");
}

/////////////////////////////////////////////////////////加载后执行

$(document).ready(function () {

	// $("#btnQuery").click(function () {
	// 	Utility.loadGridWithParams();
	// });

	al_record.initDivs();//初始化控件

});


</script>

<body style="background-color:rgb(251,251,251);height:98%;width:99%;" class="base_ver_flexStartDiv_css">
	<div id="toolbar" style="width:100%;" class="sh_css_basFontSize">
		<form id="queryForm" action="<%=ApplicationPath%>/report/paginate.action">
			<input type="hidden" name="queryId" value="alarm.selectAlarms" />
			<input type="hidden" name="fileName" value="报警信息" />
			<input type="hidden" id="alarmTypeName" name="alarmTypeName" value="所有" />
			<input type="hidden" id="alarmSourceName" name="alarmSourceName" value="所有" />

			<!--上层按钮栏-->
			<div style="width:80%;margin-left: 15px;margin-top:5px;">
				<a id="btnExport" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-excel'" 
					onclick="Utility.excelExport('<%=ApplicationPath%>/export.action');">导出</a>
				&nbsp;&nbsp;
				<a  href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="al_record.reset();">重置</a>
			</div>
			<!--下层查询工具栏-->
			<hr>
			<div style="width:100%;height:45px;" class="base_hori_flexStartDiv_css">
				<!--左侧条件样式-->
				<div style="height:100%;margin-top:7px;margin-left:10px;" class="base_ver_Around_leftDiv_css">
					<div>
						组织
						<select id="al_record_depId" name="depId" style="width:150px;"></select>
						&nbsp;
						车辆
						<input type="text" id="al_record_plateNo" name="plateNo" style="width:80px;">
						&nbsp;
						起止时间
						<input type="text" name="startTime" id="al_record_startTime" class="easyui-datetimebox" style="width:150px;" />
						<span>-</span>
						<input type="text" name="endTime" id="al_record_endTime" class="easyui-datetimebox" style="width:150px;" />
					</div>
					<div style="margin-top:7px;">
						报警来源
						<select id="al_record_alarmSource"  style="width:110px;"></select>
						&nbsp;
						报警类型
						<select id="al_record_alarmType"  style="width:140px;"></select>
						&nbsp;
						报警时长 >=
						<input id="al_record_timeSpan" type="text" name="timeSpan" style="width:40px;">(秒)
						&nbsp;
                        驾驶员
                        <input type="text" name="driverName" style="width:80px;">
					</div>
				</div>
				<!--右侧按钮-->
				<div style="margin-left:20px;" class="base_hori_flexCenterDiv_css">
					<div id="btnQuery" class="sh_css_btn" onclick="javascript:al_record.getAllDatas(1);">
						<div class="ui-icon icon-search" style="width:16px;height:16px;"></div>
						<span>查询</span>
					</div>
				</div>
			</div>

		</form>
	</div>
	<table id="al_record_queryGrid" class="easyui-datagrid" title="" style="width:100%;" data-options="pagination:true,pageSize:15,singleSelect:true,rownumbers:true,striped:true,fitColumns: true,
						pageList: [15, 20, 50, 100, 150, 200],fit:true,
						url:'<%=ApplicationPath%>/report/paginate.action',method:'get'">
		<thead>
			<tr>
				<th data-options="field:'depName'" width="10%">组织名称</th>
				<th data-options="field:'plateNo'" width="80">车牌号码</th>
				<th data-options="field:'plateColor'" width="60">车牌颜色</th>
				<th data-options="field:'alarmType'" width="100">报警类型</th>
				<th data-options="field:'alarmSource'" width="90">报警来源</th>
				<th data-options="field:'startTime'" width="120">开始时间</th>
				<th data-options="field:'endTime',formatter:getEndTimeColumn" width="120">结束时间</th>
				<th data-options="field:'timeSpan'" width="70">报警时长</th>
				<th data-options="field:'location'" width="280">报警地点</th>
				<th data-options="field:'velocity'" width="70">车速(km/h)</th>
				<th data-options="field:'driverName'" width="70">驾驶员</th>
				<th data-options="field:'altitude',formatter:al_record.formatAltitude" width="70">海拔(米)</th>
			</tr>
		</thead>

	</table>

</body>